package org.wkg.lesson10;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

public class Demo_1103 {

    public static void main(String[] args) throws InterruptedException {
        ReentrantLock lock = new ReentrantLock();
        //配合finally在try中任意一行代码出错以后，都会执行finally中的代码，在finally中写上一个释放锁代码就可以解决死锁问题。
        try {
            lock.lock();
            System.out.println("业务代码执行中....");
            TimeUnit.SECONDS.sleep(3);
            throw new InterruptedException("程序错误");
        } finally {
            System.out.println("已解锁");
            lock.unlock();
        }
    }
}
